<?php
include_once('common.inc.php');
include_once(__ROOT__.'model/user.class.php');

$act = get_param('action');
$userModel = new UserModel;

switch( $act ):

case 'add':
	if( get_param('uname') ){
		$data = get_data('user');
		$rs = $userModel->add_user($data);	
		if( $rs ){
			echo '<p>Success!</p>';
		}else{
			echo '<p>'.$userModel->get_error().'</p>';
		}
	}
	include_once(__ROOT__.'model/userGroup.class.php');
	$group = new UserGroupModel;
	$groups = $group->get_all_group();
	$strOption = "";
	foreach( $groups as $v ){
		$strOption .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
	}
	echo '
		<fieldset>
			<legend>添加用户</legend>
			<form action="user.php?action=add" method="post">
				<p>
					<label for="uname">用户名：</label>
					<input type="text" name="uname" />
				</p>
				<p>
					<label for="gid">用户组：</label>
					<select name="gid">
					'.$strOption.'
					</select>
				</p>
				<p>
					<input type="submit" value="Submit" name="submit"  />
				</p>
			</form>
		</fieldset>
	';
break;

endswitch;
